package teste;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;

import parser.MiniJavaParser;
import syntaxtree.Program;
import visitor.DepthFirstVisitor;
import visitor.PrettyPrintVisitor;
import visitor.Visitor;

public class ParserTest {
    public static void main(String args []) throws ParseException, IOException
    {
      while (true)
      {
       System.out.print("Digite o caminho do arquivo :");

       BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
       String filename = buf.readLine();

       System.out.println("Leitura do arquivo " + filename);
       try {
          MiniJavaParser parser = new MiniJavaParser(new java.io.FileInputStream(filename));
          
       }
       catch (java.io.FileNotFoundException e) {
        System.out.println("Arquivo " + filename + " nao encontrado.");
                                                    return;
               
       }
       
       try {
           Program p = MiniJavaParser.program();
           Visitor v = new PrettyPrintVisitor();
           p.accept(v);
       } catch (parser.ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
       }
       
    }
    }
}